package factories;

import logic.common.team.Team;
import logic.nodes.nodeSettings.upgrades.UpgradableSettings;
import logic.ships.autoWeaponShip.AutoWeaponShipProperties;
import logic.ships.mothership.MotherShip;

import com.jme.scene.Node;

import fileHandling.ModelImporter;
import fileHandling.SettingsLoader;

/**
 * With this class {@link MotherShip}s can be created.
 * 
 * @author Wasserleiche
 */
public class MotherShipFactory {
	
	/**
	 * Creates a new {@link MotherShip} of the given {@link Fraction}.
	 * @param fraction The {@link Fraction} the {@link MotherShip} belongs to.
	 * @return A new instance of {@link MotherShip}.
	 */
	public static MotherShip createMotherShip(Team team) {
		String fraction = team.getFraction().toString().toLowerCase();
		String motherShipPath = "data/fractions/" + fraction + "/ships/mothership/";
		
		AutoWeaponShipProperties properties = getMotherShipProperties(motherShipPath);
		if(properties == null) return null;
		
		String modelPath = properties.getModelPath();
		Node model = ModelImporter.getModel(modelPath);
		if(model == null) return null;
		
		MotherShip motherShip = new MotherShip(modelPath, "mothership", model, properties, team);
		
		return motherShip;
	}
	
	/**
	 * Creates a new {@link AutoWeaponShipProperties}-Object for the given {@link MotherShip} and returns it.
	 * @param motherShipPath The path to the {@link MotherShip} (with / at the end).
	 * @return A new {@link AutoWeaponShipProperties}-Object. null, if it could not be created.
	 */
	public static AutoWeaponShipProperties getMotherShipProperties(String motherShipPath) {
		UpgradableSettings settings = SettingsLoader.loadUpgradableSettings(motherShipPath + "properties.xml");
		return new AutoWeaponShipProperties(settings);
	}
}